/*
 * Copyright (C) 2009 Christoph Caks
 *
 * This file is part of GLWAK.
 *
 * GLWAK is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * GLWAK is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with GLWAK.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 * Log.h
 *
 *  Created on: 20.06.2009
 *      Author: Christoph Caks
 */

#ifndef LOG_H_
#define LOG_H_

#include <string>
#include <sstream>
#include <iostream>
#include <ctime>
#include <sys/time.h>

#include "OutputPolicy.h"

namespace glwak {
namespace util {

enum TLogLevel {
	logERROR,
	logWARNING,
	logINFO,
	logDEBUG,
	logDEBUG1,
	logDEBUG2,
	logDEBUG3,
	logDEBUG4
};
template <typename OutputPolicy>
class Log {
public:
	Log();
	virtual ~Log();

	std::ostringstream& getLogger( TLogLevel level = logINFO );

   static TLogLevel& getReportingLevel();

protected:
   std::ostringstream os;
   std::string formatLogLevel( TLogLevel level );

private:
   Log( const Log& );
   Log& operator = ( const Log& );

   TLogLevel messageLevel;
   static TLogLevel reportingLevel;
};

typedef Log<glwak::util::StderrOutputPolicy> StderrLog;
typedef Log<glwak::util::StdoutOutputPolicy> StdoutLog;

} // namespace util
} // namespace glwak




/**
 * Logging shortcuts
 */
#define LOG( level ) glwak::util::StdoutLog().getLogger( glwak::util::level )
#define LOG_INFO LOG( logINFO )
#define LOG_ERROR LOG( logERROR )
#define LOG_WARNING LOG( logWARNING )
#define LOG_DEBUG LOG( logDEBUG )
#define LOG_DEBUG1 LOG( logDEBUG1 )
#define LOG_DEBUG2 LOG( logDEBUG2 )
#define LOG_DEBUG3 LOG( logDEBUG3 )
#define LOG_DEBUG4 LOG( logDEBUG4 )

#include "../src/OutputPolicy.cpp"
#include "../src/Log.cpp"

#endif /* LOG_H_ */
